<template>
	<view>
		<view>
			<view style="padding:20rpx">私密相册</view>
			<view style="padding:20rpx;">
				<view style="margin-bottom:30rpx;" v-for="(item,index) in VipPhotoLabels" :key="index">
					<view style="width:100%" v-for="(itm,idx) in UserVipPhotos" :key="idx">
						<view v-if="itm.LabelID == item.value">
							<image :src="itm.Photo" mode="widthFix" style="width:100%" @click="uploadImage(index)">
							</image>
						</view>
					</view>
					<view class="photoLabels" @click="uploadImage(index)">
						<text style="float:left;">{{ item.text }}</text>
						<text style="float:right;color:#999;font-size:32rpx">+</text>
					</view>
				</view>
			</view>
			<button class="submitBtn" @click="backMyPage">保存</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				VipPhotoLabels: [],
				UserVipPhotos: [],
				uploadUrls: []
			};
		},
		onLoad() {
			this.getPhoto();
			this.getVipLabel();
		},
		methods: {
			getVipLabel() {
				this.$httpost('/Labels/VipLabel', {}).then(res => {
					if (res.code == 200) {
						this.VipPhotoLabels = res.data.VipPhotoLabels
					}
				});
			},
			getPhoto() {
				this.$httpost('/UserAction/getMyVipPhoto', {}).then(res => {
					if (res.code == 200) {
						if (res.data.UserVipPhotos !== null) {
							this.UserVipPhotos = JSON.parse(res.data.UserVipPhotos)
						}
					}
				});
			},
			uploadImage(index) {
				// console.log("点击了")
				let _that = this;
				uni.chooseMedia({
					count: 1,
					mediaType: ['image'],
					sourceType: ['album'],
					success(res) {
						// console.log(res)
						_that.savePhoto(index, res.tempFiles)
					}
				})
			},
			savePhoto(index, tempFilePaths) {

				uni.uploadFile({
					url: this.$imgUpload + '/viphoto&type=image', //仅为示例，非真实的接口地址
					filePath: tempFilePaths[0].tempFilePath,
					name: "file",
					// files: tempFilePaths,
					formData: {},
					success: (uploadFileRes) => {
						// console.log('uploadFileRes', uploadFileRes);

						let ResData = JSON.parse(uploadFileRes.data);
						this.uploadUrls = this.$baseUrl + ResData.fileName
						this.$httpost('/UserAction/saveMyVipPhoto', {
							labelID: this.VipPhotoLabels[index].value,
							uploadUrls: this.uploadUrls
						}).then(res => {
							if (res.code == 200) {

								this.UserVipPhotos = JSON.parse(res.data.UserVipPhotos)

								// this.$common.goNavPage('/myPages/pages/mypage?artisterID='+res.data.UserID)
							}
						});
					}
				});
			},
			backMyPage() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	.submitBtn {
		background-color: $globalColor;
		color: #000;
		font-size: 28rpx;
		border: 0rpx solid $globalColor;
		width: 80vw;
		height: 70rpx;
		line-height: 70rpx;
		margin: auto
	}

	.photoLabels {
		height: 40rpx;
		line-height: 40rpx;
		border: 1rpx solid #e0e0e0;
		border-radius: 0rpx 0rpx 20rpx 20rpx;
		padding: 20rpx;
	}
</style>